package com.mall.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.system.entity.Menu;
import com.mall.system.mapper.MenuMapper;
import com.mall.system.service.MenuService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 菜单服务实现类
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {
    
    @Override
    public List<Menu> selectMenuByUserId(Long userId) {
        return this.baseMapper.selectMenuByUserId(userId);
    }
    
    @Override
    public Set<String> selectMenuPermsByUserId(Long userId) {
        List<Menu> menus = this.baseMapper.selectMenuByUserId(userId);
        return menus.stream()
                .map(Menu::getPerms)
                .filter(perms -> perms != null && !perms.isEmpty())
                .collect(Collectors.toSet());
    }
    
    /**
     * 根据角色ID查询菜单列表
     * 
     * @param roleId 角色ID
     * @return 菜单列表
     */
    public List<Menu> selectMenuByRoleId(Long roleId) {
        return this.baseMapper.selectMenuByRoleId(roleId);
    }
}